package com.biboheart.sc.support.definition;

import lombok.Getter;

// 优先级
@Getter
public enum Precedence {
    PRECEDENCE_0801(TokenType.TOKEN_PLUS, 8),
    PRECEDENCE_0802(TokenType.TOKEN_MINUS, 8),
    PRECEDENCE_0901(TokenType.TOKEN_ASTERISK, 9),
    PRECEDENCE_0902(TokenType.TOKEN_SLASH, 9),
    PRECEDENCE_0903(TokenType.TOKEN_REM, 9),
    PRECEDENCE_1103(TokenType.TOKEN_DOT, 11),
    PRECEDENCE_1401(TokenType.TOKEN_LB, 14),
    PRECEDENCE_1501(TokenType.TOKEN_NULL, 15),
    PRECEDENCE_1502(TokenType.TOKEN_INTEGER, 15),
    ;
    private final TokenType type;
    private final Integer level;

    Precedence(TokenType type, Integer level) {
        this.type = type;
        this.level = level;
    }

    public static Integer getPrecedence(TokenType type) {
        for (Precedence value : Precedence.values()) {
            if (value.getType().equals(type)) {
                return value.getLevel();
            }
        }
        return 0;
    }
}
